//package com.northpool.operator.analysis.overlap;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.northpool.operator.common.algorithm.annotation.PluginInfo;
//import com.northpool.operator.common.stpclient.StpClientOperatorBase;
//import com.northpool.stpclient.bean.BaseResponse;
//import com.northpool.stpclient.modules.geoprocess.operator.IPipelineOperator;
//import com.northpool.operator.annotation.InputParam;
//import com.northpool.operator.annotation.InputParams;
//import com.northpool.stpclient.operator.annotation.OperatorInfo;
//import com.northpool.stpclient.operator.bean.*;
//import com.northpool.type.Types;
//
//import java.util.LinkedList;
//import java.util.List;
//
//@PluginInfo(
//        ref = "IntersectOperator",
//        name = "相交",
//        description = "叠加分析-相交算子",
//        run = "java -jar op-analysis-0.0.1.jar com.northpool.operator.analysis.overlap.IntersectOperator"
//)
//public class IntersectOperator extends StpClientOperatorBase {
//    String dataSourceIdA;
//    String tableNameA;
//    String spatialFieldA;
//    String sqlFilterA;
//    String dataSourceIdB;
//    String tableNameB;
//    String spatialFieldB;
//    String sqlFilterB;
//    String targetDataSourceId;
//    String targetTableName;
//    String saveType;
//
//    @InputParams({
//            @InputParam(ref = "dataSourceIdA", name = "数据源ID_A", type = TypeEnum.STRING, required = true, testValue = "kjklz"),
//            @InputParam(ref = "tableNameA", name = "数据集名称A", type = TypeEnum.STRING, required = true, testValue = "public.永久基本农田图斑"),
//            @InputParam(ref = "spatialFieldA", name = "空间字段A", type = TypeEnum.STRING, required = true, testValue = "geom"),
//            @InputParam(ref = "sqlFilterA", name = "SQL过滤条件A", type = TypeEnum.STRING, required = false, testValue = ""),
//            @InputParam(ref = "dataSourceIdB", name = "数据源ID_B", type = TypeEnum.STRING, required = true, testValue = "kjklz"),
//            @InputParam(ref = "tableNameB", name = "数据集名称B", type = TypeEnum.STRING, required = true, testValue = "public.基本农田补划数据"),
//            @InputParam(ref = "spatialFieldB", name = "空间字段B", type = TypeEnum.STRING, required = true, testValue = "geom"),
//            @InputParam(ref = "sqlFilterB", name = "SQL过滤条件B", type = TypeEnum.STRING, required = false, testValue = ""),
//            @InputParam(ref = "targetDataSourceId", name = "目标数据源ID", type = TypeEnum.STRING, required = true, testValue = "kjklz"),
//            @InputParam(ref = "targetTableName", name = "目标数据集名称", type = TypeEnum.STRING, required = true, testValue = "result.永久基本农田图斑_补划_相交"),
//            @InputParam(ref = "saveType", name = "保存类型",desc = "枚举类型: A、B", type = TypeEnum.STRING, required = false, value = "A", testValue = "A"),
//    })
//    public IntersectOperator() {
//        super();
//    }
//
//    @Override
//    public void execute() throws Exception {
//        this.saveType = params.get("saveType");
//        // 输入参数
//        if ("A".equals(this.saveType)) {
//            this.dataSourceIdA = params.get("dataSourceIdA");
//            this.tableNameA = params.get("tableNameA");
//            this.spatialFieldA = params.get("spatialFieldA");
//            this.sqlFilterA = params.get("sqlFilterA");
//            this.dataSourceIdB = params.get("dataSourceIdB");
//            this.tableNameB = params.get("tableNameB");
//            this.spatialFieldB = params.get("spatialFieldB");
//            this.sqlFilterB = params.get("sqlFilterB");
//        } else if ("B".equals(this.saveType)) {
//            this.dataSourceIdB = params.get("dataSourceIdA");
//            this.tableNameB = params.get("tableNameA");
//            this.spatialFieldB = params.get("spatialFieldA");
//            this.sqlFilterB = params.get("sqlFilterA");
//            this.dataSourceIdA = params.get("dataSourceIdB");
//            this.tableNameA = params.get("tableNameB");
//            this.spatialFieldA = params.get("spatialFieldB");
//            this.sqlFilterA = params.get("sqlFilterB");
//        } else {
//            throw new RuntimeException("saveType不正确，支持A或者B");
//        }
//
//        this.targetDataSourceId = params.get("targetDataSourceId");
//        this.targetTableName = params.get("targetTableName");
//        this.saveType = params.get("saveType");
//
//        PipelineBean pipeline = new PipelineBean();
//        DatasetBean dataSet = new DatasetBean();
//        dataSet.setDataSourceId(dataSourceIdA);
//        dataSet.setTableName(tableNameA);
//        dataSet.setSqlFilter(sqlFilterA);
//        pipeline.setDataSet(dataSet);
//
//        List<OperatorBean> ops = new LinkedList<>();
//        ops.add(buildIntersect());
//        ops.add(buildPgSink());
//
//        pipeline.setOperators(ops);
//        IPipelineOperator iPipelineOperator = this.client.pipelineOperator();
//        BaseResponse response = iPipelineOperator.startPipeline(pipeline);
//        iPipelineOperator.onStart(response.getRequestId(), () -> {
//            this.error("叠加开始");
//        });
//        iPipelineOperator.onSuccess(response.getRequestId(), () -> {
//            this.log("叠加成功");
//            this.successExit();
//        });
//        iPipelineOperator.onError(response.getRequestId(), () -> {
//            this.error("叠加失败");
//            String log = iPipelineOperator.log(response.getRequestId());
//            this.error(log);
//            this.failedExit();
//        });
//        this.waiting(24);
//    }
//
//    public OperatorBean buildIntersect() {
//        OperatorBean operatorBean = new OperatorBean();
//        operatorBean.setClassName("com.northpool.stpprocess.operator.spatial.analysis.IntersectOperator");
//
//        List<ParamBean> params = new LinkedList<>();
//        params.add(new ParamBean("originSpatialField", spatialFieldA));
//        params.add(new ParamBean("dataSourceId", dataSourceIdB));
//        params.add(new ParamBean("tableName", tableNameB));
//        params.add(new ParamBean("spatialField", spatialFieldB));
//        params.add(new ParamBean("sqlFilter", sqlFilterB));
//        params.add(new ParamBean("minArea", "0.001"));
//        operatorBean.setStartParam(params);
//
//        return operatorBean;
//    }
//
//    public OperatorBean buildPgSink() {
//        OperatorBean operatorBean = new OperatorBean();
//        operatorBean.setClassName("com.northpool.stpprocess.operator.basic.sink.PostgresSink");
//
//        List<ParamBean> params = new LinkedList<>();
//        params.add(new ParamBean("dataSourceId", targetDataSourceId));
//        params.add(new ParamBean("tableName", targetTableName));
//        params.add(new ParamBean("templateDataSourceId", dataSourceIdA));
//        params.add(new ParamBean("templateTableName", tableNameA));
//        operatorBean.setStartParam(params);
//
//        return operatorBean;
//    }
//
//}
